<template>
	<view class="content">
		<scroll-view class="example-body" scroll-y>
			<uni-grid :column="3" :show-border="false" :square="false" @change="change">
				<uni-grid-item  v-for="(item ,index) in list" :index="index" :key="index">
					<view class="grid-item-box">
						<text class="text">{{item.text}}</text>
					</view>
				</uni-grid-item>
			</uni-grid>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				list: [{
						text: 'Grid 1',
					},
					{
						text: 'Grid 2',
					},
					{
						text: 'Grid 3',
					},
					{
						text: 'Grid 4',
					},
					{
						text: 'Grid 5'
					},
					{
						text: 'Grid 6'
					},
					{
						text: 'Grid 7'
					},
					{
						text: 'Grid 8'
					},
					{
						text: 'Grid 9'
					},
					{
						text: 'Grid 10'
					},
					{
						text: 'Grid 11'
					},
					{
						text: 'Grid 12'
					},
					{
						text: 'Grid 13'
					},
					{
						text: 'Grid 14'
					},
					{
						text: 'Grid 15'
					},
					{
						text: 'Grid 6'
					}
				]
			}
		},
		methods: {
			change(e) {
				let {
					index
				} = e.detail
				this.list[index].badge && this.list[index].badge++

				uni.showToast({
					title: `点击第${index+1}个宫格`,
					icon: 'none'
				})
			},
			add() {
				this.list.push({
					text: `Grid ${this.list.length+1}`,
				});
			}
		}
	}
</script>

<style>
	/* 头条小程序组件内不能引入字体 */
	/* #ifdef MP-TOUTIAO */
	@font-face {
		font-family: uniicons;
		font-weight: normal;
		font-style: normal;
		src: url('~@/static/uni.ttf') format('truetype');
	}
	/* #endif */
	/* #ifndef APP-NVUE */
	.example-body {
		/* width: 80%; */
		height: 300px;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: center;
		padding: 0;
		font-size: 14px;
		background-color: #ffffff;
		/* height:50px; */
	}
	/* #endif */
	.text {
		font-size: 26rpx;
		margin-top: 10rpx;
	}
	.example-body {
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
	}
	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
		background-color: #DDDDDD;
	}
</style>